package cn.bdqn.web;

import cn.bdqn.service.Imp.UsersserviceImp;
import cn.bdqn.service.Usersservice;
import cn.bdqn.utils.Jsonutils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 梁非凡
 * @date 2018/8/14 15:57
 */
@WebServlet("/admend")
public class AdmendServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf-8");
        Map<String,Object> result = new HashMap<>();
        String pwd = request.getParameter("newspwd");
        String idStr = request.getParameter("uid");
        int id = Integer.parseInt(idStr);
        Usersservice usersservice=new UsersserviceImp();
        boolean b = usersservice.amend(pwd, id);
        if (b){
            result.put("code","200");
            result.put("msg","修改成功");
            String jsonResult = Jsonutils.getjson(result);
            response.getWriter().write(jsonResult);
            return;
        }else {
            result.put("code","404");
            result.put("msg","旧密码输入错误");
            String jsonResult = Jsonutils.getjson(result);
            response.getWriter().write(jsonResult);
            return;
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
